import 'package:dio/dio.dart';
import 'package:f_base_one/components/goods_info.dart';
// import 'package:f_base_one/components/shop_list%20copy.dart';
// import 'package:f_base_one/components/shop_list.dart';
import 'package:flutter/material.dart';

class MyApp22 extends StatefulWidget {
  const MyApp22({super.key});

  @override
  State<MyApp22> createState() => _MyApp22State();
}

class _MyApp22State extends State<MyApp22> {
  List goodsInfo = [];
  //网络请求需要在initState中初始化
  @override
  void initState() {
    super.initState();
    getData();
  }

  //网络请求方法
  getData() async {
    Dio dio = Dio();
    final res = await dio
        .get('https://m1.apifoxmock.com/m2/6573050-6278049-default/308369428');
    setState(() {
      goodsInfo = res.data;
    });
    print(res);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('dio网络请求'),
          backgroundColor: const Color.fromARGB(255, 238, 139, 139),
        ),
        body: ListView.separated(
            itemBuilder: (BuildContext context, int index) {
              return myGoodsInfo(
                orderInfo: goodsInfo[index],
              );
            },
            separatorBuilder: (BuildContext context, int index) {
              return const Divider(
                height: 1,
                color: Colors.black,
              );
            },
            itemCount: goodsInfo.length));
  }
}
